<template>
	<view class="modifyRate">
		<u-navbar
			:title="title" 
			left-text="" 
			@leftClick="onClickBack"
			:placeholder="true"
			:fixed="true"
			:safeAreaInsetTop="true"
		></u-navbar>
		<view class="content" v-if="modifyType === '0'">
			<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
				<text class="w-txt-999">T+1手续费设置</text>
			</view>
			<view class="setRate">
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
						微信费率<text style="color: #999999;">(%)</text>
					</view>
					<view>
						<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="WeChatRate"></u-number-box>
						
					</view>
				</view>
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
					<view>
							支付宝费率<text style="color: #999999;">(%)</text>
						</view>
						<view>
							<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="AlipayRate"></u-number-box>
						</view>
					
				</view>
			</view>
			
			<u-picker :show="dialog.show"
				:title="pickerTitle"
				:columns="maxRateList"
				itemHeight="30"
				confirmColor="#1678ff"
				@confirm="confirmDialog"
				:closeOnClickOverlay="true"
				@close="closeDialog">
			</u-picker>
			<view class="btnBox">
				<u-button text="保存" color="#fff" class="preservationBtn" @click="preservationChange(0)"></u-button>
			</view>
		</view>
		<view class="content" v-if="modifyType === '1'">
			<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
				<text class="w-txt-999">T+1费率(>1000元)</text>
			</view>
			<view class="setRate">
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
						信用卡费率<text style="color: #999999;">(%)</text>
					</view>
					<u-number-box :min="0" decimal-length="2" step="0.01" :max="3" inputWidth="50" v-model="unionScan.t1Credit"></u-number-box>
					
				</view>
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
							借记卡费率<text style="color: #999999;">(%)</text>
						</view>
						
						<u-number-box :min="0" decimal-length="2" step="0.01" :max="3" inputWidth="50" v-model="unionScan.t1Debit"></u-number-box>
				</view>
				<!-- <view class="w-flex w-flex-between w-p-tb-15 w-p-10">
					<view>
							借记卡封顶费<text style="color: #999999;">(元)</text>
						</view>
						<u-number-box :min="18" step="1" :max="50" :integer="true" inputWidth="50" v-model="unionScan.Capping"></u-number-box>
				</view> -->
			</view>
			<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
				<text class="w-txt-999">T+1费率(<=1000元)</text>
			</view>
			<view class="setRate">
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
						信用卡费率<text style="color: #999999;">(%)</text>
					</view>
					<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="unionScan2.t1Credit"></u-number-box>
					
				</view>
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
							借记卡费率<text style="color: #999999;">(%)</text>
						</view>
						
						<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="unionScan2.t1Debit"></u-number-box>
				</view>
			</view>
			
			<view class="btnBox">
				<u-button text="保存" color="#fff" class="preservationBtn" @click="preservationChange(1)"></u-button>
			</view>
			<view class="w-flex tip w-mt-15">
				<text class="circle"></text>
				<text>不超过1000元的费率为活动费率，后面根据银联政策调整</text>
			</view>
			<view class="w-flex tip">
				<text class="circle"></text>
				<text>活动费率根据政策费率计算得出，如需修改请编辑正常费率</text>
			</view>
		</view>
		<view class="content" v-if="modifyType === '2'">
			<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
				<text class="w-txt-999">T+1费率设置</text>
			</view>
			<view class="setRate">
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
						信用卡费率<text style="color: #999999;">(%)</text>
					</view>
					<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="card.t1Credit"></u-number-box>
					
				</view>
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
							借记卡费率<text style="color: #999999;">(%)</text>
						</view>
						
						<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="card.t1Debit"></u-number-box>
				</view>
				<!-- <view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
							借记卡封顶费<text style="color: #999999;">(元)</text>
						</view>
						<u-number-box :min="10" step="1" :max="50" :integer="true" inputWidth="50" v-model="card.Capping"></u-number-box>
				</view> -->
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
					<view>
							境外卡费率<text style="color: #999999;">(%)</text>
						</view>
						
						<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="card.t1OverSee"></u-number-box>
				</view>
			</view>
			<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
				<text class="w-txt-999">T+0费率设置 <text style="color: #c9c9c9;">(需要费率基础上对每次刷卡加收提现费)</text></text>
			</view>
			<view class="setRate">
				<!-- <view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
							提现手续费<text style="color: #999999;">(元/笔)</text>
						</view>
						<u-number-box :min="0" step="1" :max="50" :integer="true" inputWidth="50" v-model="card.WithdrawalRate"></u-number-box>
				</view> -->
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
						信用卡费率<text style="color: #999999;">(%)</text>
					</view>
					<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="card.t0Credit"></u-number-box>
					
				</view>
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10" style="border-bottom: 1px solid #efefef;">
					<view>
							借记卡费率<text style="color: #999999;">(%)</text>
						</view>
						
						<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="card.t0Debit"></u-number-box>
				</view>
				<view class="w-flex w-flex-between w-p-tb-15 w-p-10">
					<view>
							境外卡费率<text style="color: #999999;">(%)</text>
						</view>
						
						<u-number-box :min="0" step="0.01" decimal-length="2" :max="3" inputWidth="50" v-model="card.t0OverSee"></u-number-box>
				</view>
			</view>
			
			<view class="btnBox">
				<u-button text="保存" color="#fff" class="preservationBtn" @click="preservationChange(2)"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data () {
		return {
			title: '扫码费率',
			minRate: 0.21, // 最小费率
			maxRate: 3, // 最大费率
			WeChatRate: 0,
			AlipayRate: 0,
			dialog: {
				show: false
			},
			maxRateList: [
				[0.21, 0.22, 0.23, 0.24,0.25]
			],
			pickerTitle: '',
			singleIndex: null,
			WeChatSingleIndex: null,
			AlipaySingleIndex: null,
			defaultIndex: [],
			modifyType: '',
			unionScan: {
				// CreditCard: 0.51,
				// DebitCard: 0.41,
				// Capping: 18,
				// CreditCard1: 0.21,
				// DebitCard1: 0.21,
				t0Credit: null,
				t0Debit: null,
				t1Credit: null,
				t1Debit: null,
			},
			unionScan2: {
				t0Credit: null,
				t0Debit: null,
				t1Credit: null,
				t1Debit: null
			},
			payCard: {
				CreditCard: 0.51,
				DebitCard: 0.40,
				Capping: 18,
				OverseasCard: 2.60,
				WithdrawalRate: 0,
				CreditCard1: 0.53,
				DebitCard1: 0.42,
				OverseasCard1: 3
			},
			card: {
				t0Credit: null,
				t0Debit: null,
				t0OverSee: null,
				t1Credit: null,
				t1Debit: null,
				t1OverSee: null,
			}
		}
	},
	onLoad(e) {
		this.modifyType = e.modifyType
		if (e.modifyType === '0') {
			this.title = '扫码费率'
		} else if (e.modifyType === '1') {
			this.title = '银联二维码费率'
		} else {
			this.title = '刷卡费率'
		}
		this.getRate()
		
		
	},
	methods: {
		onClickBack () {
			uni.navigateBack()
		},
		getStorageRateInfo () {
			if (uni.getStorageSync("ScanCodeRate")) {
				this.WeChatRate = uni.getStorageSync("ScanCodeRate").WeChatRate
				this.AlipayRate = uni.getStorageSync("ScanCodeRate").AlipayRate
				
			}
			if (uni.getStorageSync("UnionPayRate")) {
				
				// this.unionScan.Capping = uni.getStorageSync("UnionPayRate").Capping;
				this.unionScan.t1Debit = uni.getStorageSync("UnionPayRate").t1Debit;
				this.unionScan.t1Credit = uni.getStorageSync("UnionPayRate").t1Credit;
				this.unionScan2.t1Debit = uni.getStorageSync("UnionPayRate").t1Debit_Scan2;
				this.unionScan2.t1Credit = uni.getStorageSync("UnionPayRate").t1Credit_Scan2;
			}
			if (uni.getStorageSync("payCard")) {
				
				this.card = uni.getStorageSync("payCard")
			}
		},
		async getRate () {
			let params = {
				user_id: uni.getStorageSync("dataUserID")
			}
			const res = await this.$API({url: '/api/user/user_rate', method:"GET", data: params})
			if (res.code === 1) {
				this.WeChatRate = res.data.weixin
				this.AlipayRate = res.data.alipay
				this.unionScan = res.data.unionScan
				this.unionScan2 = res.data.unionScan2
				this.card = res.data.card
			}
			this.getStorageRateInfo()
		},
		showDialog (type) {
			this.dialog.show = true
			if (type === 1) {
				this.pickerTitle = 'T+1微信费率'
				this.defaultIndex = this.WeChatSingleIndex || 0
			} else {
				this.pickerTitle = 'T+1支付宝费率'
				this.defaultIndex = this.AlipaySingleIndex || 0
			}
		},
		closeDialog () {
			this.dialog.show = false
		},
		confirmDialog (e) {
			if (this.pickerTitle === 'T+1微信费率') {
				this.WeChatRate = e.value[0]
				this.WeChatSingleIndex = e.indexs
			} else {
				this.AlipayRate = e.value[0]
				
				this.AlipaySingleIndex = e.indexs
			}
			
			this.dialog.show = false
		},
		preservationChange (type) {
			if (type === 0) {
				let params = {
					WeChatRate: this.WeChatRate,
					AlipayRate: this.AlipayRate
				}
				uni.setStorageSync("ScanCodeRate", params)
			}
			if (type === 1) {
				let params = {
					t1Debit: this.unionScan.t1Debit,
					t1Credit: this.unionScan.t1Credit,
					t1Debit_Scan2: this.unionScan2.t1Debit,
					t1Credit_Scan2: this.unionScan2.t1Credit,
				}
				uni.setStorageSync("UnionPayRate", params)
			}
			if (type === 2) {
				uni.setStorageSync("payCard", this.card)
			}
			uni.navigateBack()
		}
	}
}
</script>

<style lang="scss" scoped>
.modifyRate {
	.content {
		.setRate {
			background: #FFFFFF;
		}
		.txtColor {
			/deep/.u-icon__icon {
				color: #cfcfcf !important;
			}
		}
		.btnBox {
			margin-top: 40rpx;
			padding: 20rpx;
			.preservationBtn {
				background-color: #1678ff !important;
			}
		}
		/deep/ .u-number-box__minus,
		/deep/.u-number-box__plus{
			background-color: transparent !important;
		}
		.tip {
			font-size: 12px;
			padding: 4rpx 20rpx;
			color: #999;
			.circle {
				display: flex;
				align-items: center;
				width: 12rpx;
				height: 12rpx;
				border-radius: 50%;
				background: #1678ff;
				margin-right: 10rpx;
			}
		}
	}
}
</style>
